The purpose of this modification is to ensure that every normal request
[lhc/web/wiklou.git] / includes / Article.php
1 <?
2 # Class representing a Wikipedia article and history.
3 # See design.doc for an overview.
4
5 # Note: edit user interface and cache support functions have been
6 # moved to separate EditPage and CacheManager classes.
7
8 /* CHECK MERGE @@@
9 TEST THIS @@@
10
11 * s/\$wgTitle/\$this->mTitle/ performed, many replacements
12 * mTitle variable added to class
13 */
14
15 include_once( "CacheManager.php" );
16
17 class Article {
18 /* private */ var $mContent, $mContentLoaded;
19 /* private */ var $mUser, $mTimestamp, $mUserText;
20 /* private */ var $mCounter, $mComment, $mCountAdjustment;
21 /* private */ var $mMinorEdit, $mRedirectedFrom;
22 /* private */ var $mTouched, $mFileCache, $mTitle;
23
24 function Article( &$title ) {
25 $this->mTitle =& $title;
26 $this->clear();
27 }
28
29 /* private */ function clear()
30 {
31 $this->mContentLoaded = false;
32 $this->mUser = $this->mCounter = -1; # Not loaded
33 $this->mRedirectedFrom = $this->mUserText =
34 $this->mTimestamp = $this->mComment = $this->mFileCache = "";
35 $this->mCountAdjustment = 0;
36 $this->mTouched = "19700101000000";
37 }
38
39 # Note that getContent/loadContent may follow redirects if
40 # not told otherwise, and so may cause a change to mTitle.
41
42 function getContent( $noredir = false )
43 {
44 global $action,$section,$count; # From query string
45 $fname = "Article::getContent";
46 wfProfileIn( $fname );
47
48 if ( 0 == $this->getID() ) {
49 if ( "edit" == $action ) {
50 wfProfileOut( $fname );
51 return ""; # was "newarticletext", now moved above the box)
52 }
53 wfProfileOut( $fname );
54 return wfMsg( "noarticletext" );
55 } else {
56 $this->loadContent( $noredir );
57
58 if(
59 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
60 ( $this->mTitle->getNamespace() == Namespace::getTalk( Namespace::getUser()) ) &&
61 preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$this->mTitle->getText()) &&
62 $action=="view"
63 )
64 {
65 wfProfileOut( $fname );
66 return $this->mContent . "\n" .wfMsg("anontalkpagetext"); }
67 else {
68 if($action=="edit") {
69 if($section!="") {
70 if($section=="new") {
71 wfProfileOut( $fname );
72 return "";
73 }
74
75 $secs=preg_split("/(^=+.*?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)/mi",
76 $this->mContent, -1,
77 PREG_SPLIT_DELIM_CAPTURE);
78 if($section==0) {
79 wfProfileOut( $fname );
80 return trim($secs[0]);
81 } else {
82 wfProfileOut( $fname );
83 return trim($secs[$section*2-1] . $secs[$section*2]);
84 }
85 }
86 }
87 wfProfileOut( $fname );
88 return $this->mContent;
89 }
90 }
91 }
92
93 function loadContent( $noredir = false )
94 {
95 global $wgOut, $wgMwRedir;
96 global $oldid, $redirect; # From query
97
98 if ( $this->mContentLoaded ) return;
99 $fname = "Article::loadContent";
100
101 # Pre-fill content with error message so that if something
102 # fails we'll have something telling us what we intended.
103
104 $t = $this->mTitle->getPrefixedText();
105 if ( isset( $oldid ) ) {
106 $oldid = IntVal( $oldid );
107 $t .= ",oldid={$oldid}";
108 }
109 if ( isset( $redirect ) ) {
110 $redirect = ($redirect == "no") ? "no" : "yes";
111 $t .= ",redirect={$redirect}";
112 }
113 $this->mContent = wfMsg( "missingarticle", $t );
114
115 if ( ! $oldid ) { # Retrieve current version
116 $id = $this->getID();
117 if ( 0 == $id ) return;
118
119 $sql = "SELECT " .
120 "cur_text,cur_timestamp,cur_user,cur_counter,cur_restrictions,cur_touched " .
121 "FROM cur WHERE cur_id={$id}";
122 wfDebug( "$sql\n" );
123 $res = wfQuery( $sql, DB_READ, $fname );
124 if ( 0 == wfNumRows( $res ) ) {
125 return;
126 }
127
128 $s = wfFetchObject( $res );
129 # If we got a redirect, follow it (unless we've been told
130 # not to by either the function parameter or the query
131 if ( ( "no" != $redirect ) && ( false == $noredir ) &&
132 ( $wgMwRedir->matchStart( $s->cur_text ) ) ) {
133 if ( preg_match( "/\\[\\[([^\\]\\|]+)[\\]\\|]/",
134 $s->cur_text, $m ) ) {
135 $rt = Title::newFromText( $m[1] );
136
137 # Gotta hand redirects to special pages differently:
138 # Fill the HTTP response "Location" header and ignore
139 # the rest of the page we're on.
140
141 if ( $rt->getInterwiki() != "" ) {
142 $wgOut->redirect( $rt->getFullURL() ) ;
143 return;
144 }
145 if ( $rt->getNamespace() == Namespace::getSpecial() ) {
146 $wgOut->redirect( wfLocalUrl(
147 $rt->getPrefixedURL() ) );
148 return;
149 }
150 $rid = $rt->getArticleID();
151 if ( 0 != $rid ) {
152 $sql = "SELECT cur_text,cur_timestamp,cur_user," .
153 "cur_counter,cur_restrictions,cur_touched FROM cur WHERE cur_id={$rid}";
154 $res = wfQuery( $sql, DB_READ, $fname );
155
156 if ( 0 != wfNumRows( $res ) ) {
157 $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
158 $this->mTitle = $rt;
159 $s = wfFetchObject( $res );
160 }
161 }
162 }
163 }
164
165 $this->mContent = $s->cur_text;
166 $this->mUser = $s->cur_user;
167 $this->mCounter = $s->cur_counter;
168 $this->mTimestamp = $s->cur_timestamp;
169 $this->mTouched = $s->cur_touched;
170 $this->mTitle->mRestrictions = explode( ",", trim( $s->cur_restrictions ) );
171 $this->mTitle->mRestrictionsLoaded = true;
172 wfFreeResult( $res );
173 } else { # oldid set, retrieve historical version
174 $sql = "SELECT old_text,old_timestamp,old_user FROM old " .
175 "WHERE old_id={$oldid}";
176 $res = wfQuery( $sql, DB_READ, $fname );
177 if ( 0 == wfNumRows( $res ) ) { return; }
178
179 $s = wfFetchObject( $res );
180 $this->mContent = $s->old_text;
181 $this->mUser = $s->old_user;
182 $this->mCounter = 0;
183 $this->mTimestamp = $s->old_timestamp;
184 wfFreeResult( $res );
185 }
186 $this->mContentLoaded = true;
187 }
188
189 function getID() {
190 if( $this->mTitle ) {
191 return $this->mTitle->getArticleID();
192 } else {
193 return 0;
194 }
195 }
196
197 function getCount()
198 {
199 if ( -1 == $this->mCounter ) {
200 $id = $this->getID();
201 $this->mCounter = wfGetSQL( "cur", "cur_counter", "cur_id={$id}" );
202 }
203 return $this->mCounter;
204 }
205
206 # Would the given text make this article a "good" article (i.e.,
207 # suitable for including in the article count)?
208
209 function isCountable( $text )
210 {
211 global $wgUseCommaCount, $wgMwRedir;
212
213 if ( 0 != $this->mTitle->getNamespace() ) { return 0; }
214 if ( $wgMwRedir->matchStart( $text ) ) { return 0; }
215 $token = ($wgUseCommaCount ? "," : "[[" );
216 if ( false === strstr( $text, $token ) ) { return 0; }
217 return 1;
218 }
219
220 # Load the field related to the last edit time of the article.
221 # This isn't necessary for all uses, so it's only done if needed.
222
223 /* private */ function loadLastEdit()
224 {
225 global $wgOut;
226 if ( -1 != $this->mUser ) return;
227
228 $sql = "SELECT cur_user,cur_user_text,cur_timestamp," .
229 "cur_comment,cur_minor_edit FROM cur WHERE " .
230 "cur_id=" . $this->getID();
231 $res = wfQuery( $sql, DB_READ, "Article::loadLastEdit" );
232
233 if ( wfNumRows( $res ) > 0 ) {
234 $s = wfFetchObject( $res );
235 $this->mUser = $s->cur_user;
236 $this->mUserText = $s->cur_user_text;
237 $this->mTimestamp = $s->cur_timestamp;
238 $this->mComment = $s->cur_comment;
239 $this->mMinorEdit = $s->cur_minor_edit;
240 }
241 }
242
243 function getTimestamp()
244 {
245 $this->loadLastEdit();
246 return $this->mTimestamp;
247 }
248
249 function getUser()
250 {
251 $this->loadLastEdit();
252 return $this->mUser;
253 }
254
255 function getUserText()
256 {
257 $this->loadLastEdit();
258 return $this->mUserText;
259 }
260
261 function getComment()
262 {
263 $this->loadLastEdit();
264 return $this->mComment;
265 }
266
267 function getMinorEdit()
268 {
269 $this->loadLastEdit();
270 return $this->mMinorEdit;
271 }
272
273 # This is the default action of the script: just view the page of
274 # the given title.
275
276 function view()
277 {
278 global $wgUser, $wgOut, $wgLang;
279 global $oldid, $diff; # From query
280 global $wgLinkCache, $IP;
281 $fname = "Article::view";
282 wfProfileIn( $fname );
283
284 $wgOut->setArticleFlag( true );
285 $wgOut->setRobotpolicy( "index,follow" );
286
287 # If we got diff and oldid in the query, we want to see a
288 # diff page instead of the article.
289
290 if ( isset( $diff ) ) {
291 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
292 $de = new DifferenceEngine( $oldid, $diff );
293 $de->showDiffPage();
294 wfProfileOut( $fname );
295 return;
296 }
297
298 if ( !isset( $oldid ) and $this->checkTouched() ) {
299 if( $wgOut->checkLastModified( $this->mTouched ) ){
300 return;
301 } else if ( $this->tryFileCache() ) {
302 # tell wgOut that output is taken care of
303 $wgOut->disable();
304 return;
305 }
306 }
307
308 $text = $this->getContent(); # May change mTitle
309 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
310 $wgOut->setHTMLTitle( $this->mTitle->getPrefixedText() .
311 " - " . wfMsg( "wikititlesuffix" ) );
312
313 # We're looking at an old revision
314
315 if ( $oldid ) {
316 $this->setOldSubtitle();
317 $wgOut->setRobotpolicy( "noindex,follow" );
318 }
319 if ( "" != $this->mRedirectedFrom ) {
320 $sk = $wgUser->getSkin();
321 $redir = $sk->makeKnownLink( $this->mRedirectedFrom, "",
322 "redirect=no" );
323 $s = wfMsg( "redirectedfrom", $redir );
324 $wgOut->setSubtitle( $s );
325 }
326
327 $wgLinkCache->preFill( $this->mTitle );
328 $wgOut->addWikiText( $text );
329
330 $this->viewUpdates();
331 wfProfileOut( $fname );
332 }
333
334 # Theoretically we could defer these whole insert and update
335 # functions for after display, but that's taking a big leap
336 # of faith, and we want to be able to report database
337 # errors at some point.
338
339 /* private */ function insertNewArticle( $text, $summary, $isminor, $watchthis )
340 {
341 global $wgOut, $wgUser, $wgLinkCache, $wgMwRedir;
342 global $wgEnablePersistentLC;
343
344 $fname = "Article::insertNewArticle";
345
346 $this->mCountAdjustment = $this->isCountable( $text );
347
348 $ns = $this->mTitle->getNamespace();
349 $ttl = $this->mTitle->getDBkey();
350 $text = $this->preSaveTransform( $text );
351 if ( $wgMwRedir->matchStart( $text ) ) { $redir = 1; }
352 else { $redir = 0; }
353
354 $now = wfTimestampNow();
355 $won = wfInvertTimestamp( $now );
356 wfSeedRandom();
357 $rand = number_format( mt_rand() / mt_getrandmax(), 12, ".", "" );
358 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
359 "cur_comment,cur_user,cur_timestamp,cur_minor_edit,cur_counter," .
360 "cur_restrictions,cur_user_text,cur_is_redirect," .
361 "cur_is_new,cur_random,cur_touched,inverse_timestamp) VALUES ({$ns},'" . wfStrencode( $ttl ) . "', '" .
362 wfStrencode( $text ) . "', '" .
363 wfStrencode( $summary ) . "', '" .
364 $wgUser->getID() . "', '{$now}', " .
365 ( $isminor ? 1 : 0 ) . ", 0, '', '" .
366 wfStrencode( $wgUser->getName() ) . "', $redir, 1, $rand, '{$now}', '{$won}')";
367 $res = wfQuery( $sql, DB_WRITE, $fname );
368
369 $newid = wfInsertId();
370 $this->mTitle->resetArticleID( $newid );
371
372 if ( $wgEnablePersistentLC ) {
373 // Purge related entries in links cache on new page, to heal broken links
374 $ptitle = wfStrencode( $ttl );
375 wfQuery("DELETE linkscc FROM linkscc,brokenlinks ".
376 "WHERE lcc_pageid=bl_from AND bl_to='{$ptitle}'", DB_WRITE);
377 }
378
379 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
380 "rc_namespace,rc_title,rc_new,rc_minor,rc_cur_id,rc_user," .
381 "rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid,rc_bot) VALUES (" .
382 "'{$now}','{$now}',{$ns},'" . wfStrencode( $ttl ) . "',1," .
383 ( $isminor ? 1 : 0 ) . ",{$newid}," . $wgUser->getID() . ",'" .
384 wfStrencode( $wgUser->getName() ) . "','" .
385 wfStrencode( $summary ) . "',0,0," .
386 ( $wgUser->isBot() ? 1 : 0 ) . ")";
387 wfQuery( $sql, DB_WRITE, $fname );
388 if ($watchthis) {
389 if(!$this->mTitle->userIsWatching()) $this->watch();
390 } else {
391 if ( $this->mTitle->userIsWatching() ) {
392 $this->unwatch();
393 }
394 }
395
396 # The talk page isn't in the regular link tables, so we need to update manually:
397 $talkns = $ns ^ 1; # talk -> normal; normal -> talk
398 $sql = "UPDATE cur set cur_touched='$now' WHERE cur_namespace=$talkns AND cur_title='" . wfStrencode( $ttl ) . "'";
399 wfQuery( $sql, DB_WRITE );
400
401 $this->showArticle( $text, wfMsg( "newarticle" ) );
402 }
403
404 function updateArticle( $text, $summary, $minor, $watchthis, $section = "")
405 {
406 global $wgOut, $wgUser, $wgLinkCache;
407 global $wgDBtransactions, $wgMwRedir;
408 $fname = "Article::updateArticle";
409
410 $this->loadLastEdit();
411
412 // insert updated section into old text if we have only edited part
413 // of the article
414 if ($section != "") {
415 $oldtext=$this->getContent();
416 if($section=="new") {
417 if($summary) $subject="== {$summary} ==\n\n";
418 $text=$oldtext."\n\n".$subject.$text;
419 } else {
420 $secs=preg_split("/(^=+.*?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)/mi",
421 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE);
422 $secs[$section*2]=$text."\n\n"; // replace with edited
423 if($section) { $secs[$section*2-1]=""; } // erase old headline
424 $text=join("",$secs);
425 }
426 }
427 if ( $this->mMinorEdit ) { $me1 = 1; } else { $me1 = 0; }
428 if ( $minor ) { $me2 = 1; } else { $me2 = 0; }
429 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ")[^\\n]+)/i", $text, $m ) ) {
430 $redir = 1;
431 $text = $m[1] . "\n"; # Remove all content but redirect
432 }
433 else { $redir = 0; }
434
435 $text = $this->preSaveTransform( $text );
436
437 # Update article, but only if changed.
438
439 if( $wgDBtransactions ) {
440 $sql = "BEGIN";
441 wfQuery( $sql, DB_WRITE );
442 }
443 $oldtext = $this->getContent( true );
444
445 if ( 0 != strcmp( $text, $oldtext ) ) {
446 $this->mCountAdjustment = $this->isCountable( $text )
447 - $this->isCountable( $oldtext );
448
449 $now = wfTimestampNow();
450 $won = wfInvertTimestamp( $now );
451 $sql = "UPDATE cur SET cur_text='" . wfStrencode( $text ) .
452 "',cur_comment='" . wfStrencode( $summary ) .
453 "',cur_minor_edit={$me2}, cur_user=" . $wgUser->getID() .
454 ",cur_timestamp='{$now}',cur_user_text='" .
455 wfStrencode( $wgUser->getName() ) .
456 "',cur_is_redirect={$redir}, cur_is_new=0, cur_touched='{$now}', inverse_timestamp='{$won}' " .
457 "WHERE cur_id=" . $this->getID() .
458 " AND cur_timestamp='" . $this->getTimestamp() . "'";
459 $res = wfQuery( $sql, DB_WRITE, $fname );
460
461 if( wfAffectedRows() == 0 ) {
462 /* Belated edit conflict! Run away!! */
463 return false;
464 }
465
466 $sql = "INSERT INTO old (old_namespace,old_title,old_text," .
467 "old_comment,old_user,old_user_text,old_timestamp," .
468 "old_minor_edit,inverse_timestamp) VALUES (" .
469 $this->mTitle->getNamespace() . ", '" .
470 wfStrencode( $this->mTitle->getDBkey() ) . "', '" .
471 wfStrencode( $oldtext ) . "', '" .
472 wfStrencode( $this->getComment() ) . "', " .
473 $this->getUser() . ", '" .
474 wfStrencode( $this->getUserText() ) . "', '" .
475 $this->getTimestamp() . "', " . $me1 . ", '" .
476 wfInvertTimestamp( $this->getTimestamp() ) . "')";
477 $res = wfQuery( $sql, DB_WRITE, $fname );
478 $oldid = wfInsertID( $res );
479
480 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
481 "rc_namespace,rc_title,rc_new,rc_minor,rc_bot,rc_cur_id,rc_user," .
482 "rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid) VALUES (" .
483 "'{$now}','{$now}'," . $this->mTitle->getNamespace() . ",'" .
484 wfStrencode( $this->mTitle->getDBkey() ) . "',0,{$me2}," .
485 ( $wgUser->isBot() ? 1 : 0 ) . "," .
486 $this->getID() . "," . $wgUser->getID() . ",'" .
487 wfStrencode( $wgUser->getName() ) . "','" .
488 wfStrencode( $summary ) . "',0,{$oldid})";
489 wfQuery( $sql, DB_WRITE, $fname );
490
491 $sql = "UPDATE recentchanges SET rc_this_oldid={$oldid} " .
492 "WHERE rc_namespace=" . $this->mTitle->getNamespace() . " AND " .
493 "rc_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' AND " .
494 "rc_timestamp='" . $this->getTimestamp() . "'";
495 wfQuery( $sql, DB_WRITE, $fname );
496
497 $sql = "UPDATE recentchanges SET rc_cur_time='{$now}' " .
498 "WHERE rc_cur_id=" . $this->getID();
499 wfQuery( $sql, DB_WRITE, $fname );
500
501 global $wgEnablePersistentLC;
502 if ( $wgEnablePersistentLC ) {
503 // Purge link cache for this page
504 $pageid=$this->getID();
505 wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pageid}'", DB_WRITE);
506 }
507 }
508
509 if( $wgDBtransactions ) {
510 $sql = "COMMIT";
511 wfQuery( $sql, DB_WRITE );
512 }
513
514 if ($watchthis) {
515 if (!$this->mTitle->userIsWatching()) $this->watch();
516 } else {
517 if ( $this->mTitle->userIsWatching() ) {
518 $this->unwatch();
519 }
520 }
521
522 $this->showArticle( $text, wfMsg( "updated" ) );
523 return true;
524 }
525
526 # After we've either updated or inserted the article, update
527 # the link tables and redirect to the new page.
528
529 function showArticle( $text, $subtitle )
530 {
531 global $wgOut, $wgUser, $wgLinkCache, $wgUseBetterLinksUpdate;
532 global $wgMwRedir;
533
534 $wgLinkCache = new LinkCache();
535
536 # Get old version of link table to allow incremental link updates
537 if ( $wgUseBetterLinksUpdate ) {
538 $wgLinkCache->preFill( $this->mTitle );
539 $wgLinkCache->clear();
540 }
541
542 # Now update the link cache by parsing the text
543 $wgOut = new OutputPage();
544 $wgOut->addWikiText( $text );
545
546 $this->editUpdates( $text );
547 if( $wgMwRedir->matchStart( $text ) )
548 $r = "redirect=no";
549 else
550 $r = "";
551 $wgOut->redirect( wfLocalUrl( $this->mTitle->getPrefixedURL(), $r ) );
552 }
553
554 # Add this page to my watchlist
555
556 function watch( $add = true )
557 {
558 global $wgUser, $wgOut, $wgLang;
559 global $wgDeferredUpdateList;
560
561 if ( 0 == $wgUser->getID() ) {
562 $wgOut->errorpage( "watchnologin", "watchnologintext" );
563 return;
564 }
565 if ( wfReadOnly() ) {
566 $wgOut->readOnlyPage();
567 return;
568 }
569 if( $add )
570 $wgUser->addWatch( $this->mTitle );
571 else
572 $wgUser->removeWatch( $this->mTitle );
573
574 $wgOut->setPagetitle( wfMsg( $add ? "addedwatch" : "removedwatch" ) );
575 $wgOut->setRobotpolicy( "noindex,follow" );
576
577 $sk = $wgUser->getSkin() ;
578 $link = $sk->makeKnownLink ( $this->mTitle->getPrefixedText() ) ;
579
580 if($add)
581 $text = wfMsg( "addedwatchtext", $link );
582 else
583 $text = wfMsg( "removedwatchtext", $link );
584 $wgOut->addHTML( $text );
585
586 $up = new UserUpdate();
587 array_push( $wgDeferredUpdateList, $up );
588
589 $wgOut->returnToMain( false );
590 }
591
592 function unwatch()
593 {
594 $this->watch( false );
595 }
596
597 # This shares a lot of issues (and code) with Recent Changes
598
599 function history()
600 {
601 global $wgUser, $wgOut, $wgLang, $offset, $limit;
602
603 # If page hasn't changed, client can cache this
604
605 if( $wgOut->checkLastModified( $this->getTimestamp() ) ){
606 # Client cache fresh and headers sent, nothing more to do.
607 return;
608 }
609 $fname = "Article::history";
610 wfProfileIn( $fname );
611
612 $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
613 $wgOut->setSubtitle( wfMsg( "revhistory" ) );
614 $wgOut->setArticleFlag( false );
615 $wgOut->setRobotpolicy( "noindex,nofollow" );
616
617 if( $this->mTitle->getArticleID() == 0 ) {
618 $wgOut->addHTML( wfMsg( "nohistory" ) );
619 wfProfileOut( $fname );
620 return;
621 }
622
623 $offset = (int)$offset;
624 $limit = (int)$limit;
625 if( $limit == 0 ) $limit = 50;
626 $namespace = $this->mTitle->getNamespace();
627 $title = $this->mTitle->getText();
628 $sql = "SELECT old_id,old_user," .
629 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
630 "FROM old USE INDEX (name_title_timestamp) " .
631 "WHERE old_namespace={$namespace} AND " .
632 "old_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " .
633 "ORDER BY inverse_timestamp LIMIT $offset, $limit";
634 $res = wfQuery( $sql, DB_READ, "Article::history" );
635
636 $revs = wfNumRows( $res );
637 if( $this->mTitle->getArticleID() == 0 ) {
638 $wgOut->addHTML( wfMsg( "nohistory" ) );
639 wfProfileOut( $fname );
640 return;
641 }
642
643 $sk = $wgUser->getSkin();
644 $numbar = wfViewPrevNext(
645 $offset, $limit,
646 $this->mTitle->getPrefixedText(),
647 "action=history" );
648 $s = $numbar;
649 $s .= $sk->beginHistoryList();
650
651 if($offset == 0 )
652 $s .= $sk->historyLine( $this->getTimestamp(), $this->getUser(),
653 $this->getUserText(), $namespace,
654 $title, 0, $this->getComment(),
655 ( $this->getMinorEdit() > 0 ) );
656
657 $revs = wfNumRows( $res );
658 while ( $line = wfFetchObject( $res ) ) {
659 $s .= $sk->historyLine( $line->old_timestamp, $line->old_user,
660 $line->old_user_text, $namespace,
661 $title, $line->old_id,
662 $line->old_comment, ( $line->old_minor_edit > 0 ) );
663 }
664 $s .= $sk->endHistoryList();
665 $s .= $numbar;
666 $wgOut->addHTML( $s );
667 wfProfileOut( $fname );
668 }
669
670 function protect( $limit = "sysop" )
671 {
672 global $wgUser, $wgOut;
673
674 if ( ! $wgUser->isSysop() ) {
675 $wgOut->sysopRequired();
676 return;
677 }
678 if ( wfReadOnly() ) {
679 $wgOut->readOnlyPage();
680 return;
681 }
682 $id = $this->mTitle->getArticleID();
683 if ( 0 == $id ) {
684 $wgOut->fatalEror( wfMsg( "badarticleerror" ) );
685 return;
686 }
687 $sql = "UPDATE cur SET cur_touched='" . wfTimestampNow() . "'," .
688 "cur_restrictions='{$limit}' WHERE cur_id={$id}";
689 wfQuery( $sql, DB_WRITE, "Article::protect" );
690
691 $log = new LogPage( wfMsg( "protectlogpage" ), wfMsg( "protectlogtext" ) );
692 if ( $limit === "" ) {
693 $log->addEntry( wfMsg( "unprotectedarticle", $this->mTitle->getPrefixedText() ), "" );
694 } else {
695 $log->addEntry( wfMsg( "protectedarticle", $this->mTitle->getPrefixedText() ), "" );
696 }
697 $wgOut->redirect( wfLocalUrl( $this->mTitle->getPrefixedURL() ) );
698 }
699
700 function unprotect()
701 {
702 return $this->protect( "" );
703 }
704
705 function delete()
706 {
707 global $wgUser, $wgOut;
708 global $wpConfirm, $wpReason, $image, $oldimage;
709
710 # This code desperately needs to be totally rewritten
711
712 if ( ( ! $wgUser->isSysop() ) ) {
713 $wgOut->sysopRequired();
714 return;
715 }
716 if ( wfReadOnly() ) {
717 $wgOut->readOnlyPage();
718 return;
719 }
720
721 # Better double-check that it hasn't been deleted yet!
722 $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
723 if ( ( "" == trim( $this->mTitle->getText() ) )
724 or ( $this->mTitle->getArticleId() == 0 ) ) {
725 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
726 return;
727 }
728
729 if ( $_POST["wpConfirm"] ) {
730 $this->doDelete();
731 return;
732 }
733
734 # determine whether this page has earlier revisions
735 # and insert a warning if it does
736 # we select the text because it might be useful below
737 $ns = $this->mTitle->getNamespace();
738 $title = $this->mTitle->getDBkey();
739 $etitle = wfStrencode( $title );
740 $sql = "SELECT old_text FROM old WHERE old_namespace=$ns and old_title='$etitle' ORDER BY inverse_timestamp LIMIT 1";
741 $res = wfQuery( $sql, DB_READ, $fname );
742 if( ($old=wfFetchObject($res)) && !$wpConfirm ) {
743 $skin=$wgUser->getSkin();
744 $wgOut->addHTML("<B>".wfMsg("historywarning"));
745 $wgOut->addHTML( $skin->historyLink() ."</B><P>");
746 }
747
748 $sql="SELECT cur_text FROM cur WHERE cur_namespace=$ns and cur_title='$etitle'";
749 $res=wfQuery($sql, DB_READ, $fname);
750 if( ($s=wfFetchObject($res))) {
751
752 # if this is a mini-text, we can paste part of it into the deletion reason
753
754 #if this is empty, an earlier revision may contain "useful" text
755 if($s->cur_text!="") {
756 $text=$s->cur_text;
757 } else {
758 if($old) {
759 $text=$old->old_text;
760 $blanked=1;
761 }
762
763 }
764
765 $length=strlen($text);
766
767 # this should not happen, since it is not possible to store an empty, new
768 # page. Let's insert a standard text in case it does, though
769 if($length==0 && !$wpReason) { $wpReason=wfmsg("exblank");}
770
771
772 if($length < 500 && !$wpReason) {
773
774 # comment field=255, let's grep the first 150 to have some user
775 # space left
776 $text=substr($text,0,150);
777 # let's strip out newlines and HTML tags
778 $text=preg_replace("/\"/","'",$text);
779 $text=preg_replace("/\</","&lt;",$text);
780 $text=preg_replace("/\>/","&gt;",$text);
781 $text=preg_replace("/[\n\r]/","",$text);
782 if(!$blanked) {
783 $wpReason=wfMsg("excontent"). " '".$text;
784 } else {
785 $wpReason=wfMsg("exbeforeblank") . " '".$text;
786 }
787 if($length>150) { $wpReason .= "..."; } # we've only pasted part of the text
788 $wpReason.="'";
789 }
790 }
791
792 return $this->confirmDelete();
793 }
794
795 function confirmDelete( $par = "" )
796 {
797 global $wgOut;
798 global $wpReason;
799
800 wfDebug( "Article::confirmDelete\n" );
801
802 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
803 $wgOut->setSubtitle( wfMsg( "deletesub", $sub ) );
804 $wgOut->setRobotpolicy( "noindex,nofollow" );
805 $wgOut->addWikiText( wfMsg( "confirmdeletetext" ) );
806
807 $t = $this->mTitle->getPrefixedURL();
808
809 $formaction = wfEscapeHTML( wfLocalUrl( $t, "action=delete" . $par ) );
810 $confirm = wfMsg( "confirm" );
811 $check = wfMsg( "confirmcheck" );
812 $delcom = wfMsg( "deletecomment" );
813
814 $wgOut->addHTML( "
815 <form id=\"deleteconfirm\" method=\"post\" action=\"{$formaction}\">
816 <table border=0><tr><td align=right>
817 {$delcom}:</td><td align=left>
818 <input type=text size=60 name=\"wpReason\" value=\"" . htmlspecialchars( $wpReason ) . "\">
819 </td></tr><tr><td>&nbsp;</td></tr>
820 <tr><td align=right>
821 <input type=checkbox name=\"wpConfirm\" value='1' id=\"wpConfirm\">
822 </td><td><label for=\"wpConfirm\">{$check}</label></td>
823 </tr><tr><td>&nbsp;</td><td>
824 <input type=submit name=\"wpConfirmB\" value=\"{$confirm}\">
825 </td></tr></table></form>\n" );
826
827 $wgOut->returnToMain( false );
828 }
829
830 function doDelete()
831 {
832 global $wgOut, $wgUser, $wgLang;
833 global $wpReason;
834 $fname = "Article::doDelete";
835 wfDebug( "$fname\n" );
836
837 $this->doDeleteArticle( $this->mTitle );
838 $deleted = $this->mTitle->getPrefixedText();
839
840 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
841 $wgOut->setRobotpolicy( "noindex,nofollow" );
842
843 $sk = $wgUser->getSkin();
844 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
845 Namespace::getWikipedia() ) .
846 ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
847
848 $text = wfMsg( "deletedtext", $deleted, $loglink );
849
850 $wgOut->addHTML( "<p>" . $text );
851 $wgOut->returnToMain( false );
852 }
853
854 function doDeleteArticle( $title )
855 {
856 global $wgUser, $wgOut, $wgLang, $wpReason, $wgDeferredUpdateList,
857 $wgEnablePersistentLC;
858
859 $fname = "Article::doDeleteArticle";
860 wfDebug( "$fname\n" );
861
862 $ns = $title->getNamespace();
863 $t = wfStrencode( $title->getDBkey() );
864 $id = $title->getArticleID();
865
866 if ( "" == $t ) {
867 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
868 return;
869 }
870
871 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
872 array_push( $wgDeferredUpdateList, $u );
873
874 # Move article and history to the "archive" table
875 $sql = "INSERT INTO archive (ar_namespace,ar_title,ar_text," .
876 "ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit," .
877 "ar_flags) SELECT cur_namespace,cur_title,cur_text,cur_comment," .
878 "cur_user,cur_user_text,cur_timestamp,cur_minor_edit,0 FROM cur " .
879 "WHERE cur_namespace={$ns} AND cur_title='{$t}'";
880 wfQuery( $sql, DB_WRITE, $fname );
881
882 $sql = "INSERT INTO archive (ar_namespace,ar_title,ar_text," .
883 "ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit," .
884 "ar_flags) SELECT old_namespace,old_title,old_text,old_comment," .
885 "old_user,old_user_text,old_timestamp,old_minor_edit,old_flags " .
886 "FROM old WHERE old_namespace={$ns} AND old_title='{$t}'";
887 wfQuery( $sql, DB_WRITE, $fname );
888
889 # Now that it's safely backed up, delete it
890
891 $sql = "DELETE FROM cur WHERE cur_namespace={$ns} AND " .
892 "cur_title='{$t}'";
893 wfQuery( $sql, DB_WRITE, $fname );
894
895 $sql = "DELETE FROM old WHERE old_namespace={$ns} AND " .
896 "old_title='{$t}'";
897 wfQuery( $sql, DB_WRITE, $fname );
898
899 $sql = "DELETE FROM recentchanges WHERE rc_namespace={$ns} AND " .
900 "rc_title='{$t}'";
901 wfQuery( $sql, DB_WRITE, $fname );
902
903 # Finally, clean up the link tables
904
905 if ( 0 != $id ) {
906
907 $t = wfStrencode( $title->getPrefixedDBkey() );
908
909 if ( $wgEnablePersistentLC ) {
910 // Purge related entries in links cache on delete,
911 wfQuery("DELETE linkscc FROM linkscc,links ".
912 "WHERE lcc_title=links.l_from AND l_to={$id}", DB_WRITE);
913 wfQuery("DELETE FROM linkscc WHERE lcc_title='{$t}'", DB_WRITE);
914 }
915
916 $sql = "SELECT l_from FROM links WHERE l_to={$id}";
917 $res = wfQuery( $sql, DB_READ, $fname );
918
919 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
920 $now = wfTimestampNow();
921 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
922 $first = true;
923
924 while ( $s = wfFetchObject( $res ) ) {
925 $nt = Title::newFromDBkey( $s->l_from );
926 $lid = $nt->getArticleID();
927
928 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
929 $first = false;
930 $sql .= "({$lid},'{$t}')";
931 $sql2 .= "{$lid}";
932 }
933 $sql2 .= ")";
934 if ( ! $first ) {
935 wfQuery( $sql, DB_WRITE, $fname );
936 wfQuery( $sql2, DB_WRITE, $fname );
937 }
938 wfFreeResult( $res );
939
940 $sql = "DELETE FROM links WHERE l_to={$id}";
941 wfQuery( $sql, DB_WRITE, $fname );
942
943 $sql = "DELETE FROM links WHERE l_from='{$t}'";
944 wfQuery( $sql, DB_WRITE, $fname );
945
946 $sql = "DELETE FROM imagelinks WHERE il_from='{$t}'";
947 wfQuery( $sql, DB_WRITE, $fname );
948
949 $sql = "DELETE FROM brokenlinks WHERE bl_from={$id}";
950 wfQuery( $sql, DB_WRITE, $fname );
951 }
952
953 $log = new LogPage( wfMsg( "dellogpage" ), wfMsg( "dellogpagetext" ) );
954 $art = $title->getPrefixedText();
955 $wpReason = wfCleanQueryVar( $wpReason );
956 $log->addEntry( wfMsg( "deletedarticle", $art ), $wpReason );
957
958 # Clear the cached article id so the interface doesn't act like we exist
959 $this->mTitle->resetArticleID( 0 );
960 $this->mTitle->mArticleID = 0;
961 }
962
963 function rollback()
964 {
965 global $wgUser, $wgLang, $wgOut, $from;
966
967 if ( ! $wgUser->isSysop() ) {
968 $wgOut->sysopRequired();
969 return;
970 }
971 if ( wfReadOnly() ) {
972 $wgOut->readOnlyPage( $this->getContent() );
973 return;
974 }
975
976 # Replace all this user's current edits with the next one down
977 $tt = wfStrencode( $this->mTitle->getDBKey() );
978 $n = $this->mTitle->getNamespace();
979
980 # Get the last editor
981 $sql = "SELECT cur_id,cur_user,cur_user_text,cur_comment FROM cur WHERE cur_title='{$tt}' AND cur_namespace={$n}";
982 $res = wfQuery( $sql, DB_READ );
983 if( ($x = wfNumRows( $res )) != 1 ) {
984 # Something wrong
985 $wgOut->addHTML( wfMsg( "notanarticle" ) );
986 return;
987 }
988 $s = wfFetchObject( $res );
989 $ut = wfStrencode( $s->cur_user_text );
990 $uid = $s->cur_user;
991 $pid = $s->cur_id;
992
993 $from = str_replace( '_', ' ', wfCleanQueryVar( $from ) );
994 if( $from != $s->cur_user_text ) {
995 $wgOut->setPageTitle(wfmsg("rollbackfailed"));
996 $wgOut->addWikiText( wfMsg( "alreadyrolled",
997 htmlspecialchars( $this->mTitle->getPrefixedText()),
998 htmlspecialchars( $from ),
999 htmlspecialchars( $s->cur_user_text ) ) );
1000 if($s->cur_comment != "") {
1001 $wgOut->addHTML(
1002 wfMsg("editcomment",
1003 htmlspecialchars( $s->cur_comment ) ) );
1004 }
1005 return;
1006 }
1007
1008 # Get the last edit not by this guy
1009 $sql = "SELECT old_text,old_user,old_user_text
1010 FROM old USE INDEX (name_title_timestamp)
1011 WHERE old_namespace={$n} AND old_title='{$tt}'
1012 AND (old_user <> {$uid} OR old_user_text <> '{$ut}')
1013 ORDER BY inverse_timestamp LIMIT 1";
1014 $res = wfQuery( $sql, DB_READ );
1015 if( wfNumRows( $res ) != 1 ) {
1016 # Something wrong
1017 $wgOut->setPageTitle(wfMsg("rollbackfailed"));
1018 $wgOut->addHTML( wfMsg( "cantrollback" ) );
1019 return;
1020 }
1021 $s = wfFetchObject( $res );
1022
1023 # Save it!
1024 $newcomment = wfMsg( "revertpage", $s->old_user_text );
1025 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
1026 $wgOut->setRobotpolicy( "noindex,nofollow" );
1027 $wgOut->addHTML( "<h2>" . $newcomment . "</h2>\n<hr>\n" );
1028 $this->updateArticle( $s->old_text, $newcomment, 1, $this->mTitle->userIsWatching() );
1029
1030 global $wgEnablePersistentLC;
1031 if ( $wgEnablePersistentLC ) {
1032 wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pid}'", DB_WRITE);
1033 }
1034
1035 $wgOut->returnToMain( false );
1036 }
1037
1038
1039 # Do standard deferred updates after page view
1040
1041 /* private */ function viewUpdates()
1042 {
1043 global $wgDeferredUpdateList;
1044
1045 if ( 0 != $this->getID() ) {
1046 global $wgDisableCounters;
1047 if( !$wgDisableCounters ) {
1048 $u = new ViewCountUpdate( $this->getID() );
1049 array_push( $wgDeferredUpdateList, $u );
1050 $u = new SiteStatsUpdate( 1, 0, 0 );
1051 array_push( $wgDeferredUpdateList, $u );
1052 }
1053 $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
1054 $this->mTitle->getDBkey() );
1055 array_push( $wgDeferredUpdateList, $u );
1056 }
1057 }
1058
1059 # Do standard deferred updates after page edit.
1060 # Every 1000th edit, prune the recent changes table.
1061
1062 /* private */ function editUpdates( $text )
1063 {
1064 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
1065
1066 wfSeedRandom();
1067 if ( 0 == mt_rand( 0, 999 ) ) {
1068 $cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
1069 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
1070 wfQuery( $sql, DB_WRITE );
1071 }
1072 $id = $this->getID();
1073 $title = $this->mTitle->getPrefixedDBkey();
1074 $adj = $this->mCountAdjustment;
1075
1076 if ( 0 != $id ) {
1077 $u = new LinksUpdate( $id, $title );
1078 array_push( $wgDeferredUpdateList, $u );
1079 $u = new SiteStatsUpdate( 0, 1, $adj );
1080 array_push( $wgDeferredUpdateList, $u );
1081 $u = new SearchUpdate( $id, $title, $text );
1082 array_push( $wgDeferredUpdateList, $u );
1083
1084 $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(),
1085 $this->mTitle->getDBkey() );
1086 array_push( $wgDeferredUpdateList, $u );
1087
1088 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1089 $messageCache = $wgMemc->get( "$wgDBname:messages" );
1090
1091 # If another thread is loading, poll
1092 for ( $i=0; $i<70 && $messageCache == 'loading'; $i++ ) {
1093 sleep(1);
1094 $messageCache = $wgMemc->get( "$wgDBname:messages" );
1095 }
1096
1097 if ( !$messageCache || $messageCache == 'loading' ) {
1098 $messageCache = wfLoadAllMessages();
1099 }
1100 $messageCache[$this->mTitle->getDBkey()] = $text;
1101 $wgMemc->set( "$wgDBname:messages", $messageCache, 86400 );
1102 }
1103 }
1104 }
1105
1106 /* private */ function setOldSubtitle()
1107 {
1108 global $wgLang, $wgOut;
1109
1110 $td = $wgLang->timeanddate( $this->mTimestamp, true );
1111 $r = wfMsg( "revisionasof", $td );
1112 $wgOut->setSubtitle( "({$r})" );
1113 }
1114
1115 # This function is called right before saving the wikitext,
1116 # so we can do things like signatures and links-in-context.
1117
1118 function preSaveTransform( $text )
1119 {
1120 $s = "";
1121 while ( "" != $text ) {
1122 $p = preg_split( "/<\\s*nowiki\\s*>/i", $text, 2 );
1123 $s .= $this->pstPass2( $p[0] );
1124
1125 if ( ( count( $p ) < 2 ) || ( "" == $p[1] ) ) { $text = ""; }
1126 else {
1127 $q = preg_split( "/<\\/\\s*nowiki\\s*>/i", $p[1], 2 );
1128 $s .= "<nowiki>{$q[0]}</nowiki>";
1129 $text = $q[1];
1130 }
1131 }
1132 return rtrim( $s );
1133 }
1134
1135 /* private */ function pstPass2( $text )
1136 {
1137 global $wgUser, $wgLang, $wgLocaltimezone;
1138
1139 # Signatures
1140 #
1141 $n = $wgUser->getName();
1142 $k = $wgUser->getOption( "nickname" );
1143 if ( "" == $k ) { $k = $n; }
1144 if(isset($wgLocaltimezone)) {
1145 $oldtz = getenv("TZ"); putenv("TZ=$wgLocaltimezone");
1146 }
1147 /* Note: this is an ugly timezone hack for the European wikis */
1148 $d = $wgLang->timeanddate( date( "YmdHis" ), false ) .
1149 " (" . date( "T" ) . ")";
1150 if(isset($wgLocaltimezone)) putenv("TZ=$oldtz");
1151
1152 $text = preg_replace( "/~~~~/", "[[" . $wgLang->getNsText(
1153 Namespace::getUser() ) . ":$n|$k]] $d", $text );
1154 $text = preg_replace( "/~~~/", "[[" . $wgLang->getNsText(
1155 Namespace::getUser() ) . ":$n|$k]]", $text );
1156
1157 # Context links: [[|name]] and [[name (context)|]]
1158 #
1159 $tc = "[&;%\\-,.\\(\\)' _0-9A-Za-z\\/:\\x80-\\xff]";
1160 $np = "[&;%\\-,.' _0-9A-Za-z\\/:\\x80-\\xff]"; # No parens
1161 $namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii!
1162 $conpat = "/^({$np}+) \\(({$tc}+)\\)$/";
1163
1164 $p1 = "/\[\[({$np}+) \\(({$np}+)\\)\\|]]/"; # [[page (context)|]]
1165 $p2 = "/\[\[\\|({$tc}+)]]/"; # [[|page]]
1166 $p3 = "/\[\[($namespacechar+):({$np}+)\\|]]/"; # [[namespace:page|]]
1167 $p4 = "/\[\[($namespacechar+):({$np}+) \\(({$np}+)\\)\\|]]/";
1168 # [[ns:page (cont)|]]
1169 $context = "";
1170 $t = $this->mTitle->getText();
1171 if ( preg_match( $conpat, $t, $m ) ) {
1172 $context = $m[2];
1173 }
1174 $text = preg_replace( $p4, "[[\\1:\\2 (\\3)|\\2]]", $text );
1175 $text = preg_replace( $p1, "[[\\1 (\\2)|\\1]]", $text );
1176 $text = preg_replace( $p3, "[[\\1:\\2|\\2]]", $text );
1177
1178 if ( "" == $context ) {
1179 $text = preg_replace( $p2, "[[\\1]]", $text );
1180 } else {
1181 $text = preg_replace( $p2, "[[\\1 ({$context})|\\1]]", $text );
1182 }
1183
1184 # {{SUBST:xxx}} variables
1185 #
1186 $mw =& MagicWord::get( MAG_SUBST );
1187 $text = $mw->substituteCallback( $text, "wfReplaceSubstVar" );
1188
1189 /* Experimental:
1190 # Trim trailing whitespace
1191 # MAG_END (__END__) tag allows for trailing
1192 # whitespace to be deliberately included
1193 $text = rtrim( $text );
1194 $mw =& MagicWord::get( MAG_END );
1195 $mw->matchAndRemove( $text );
1196 */
1197 return $text;
1198 }
1199
1200 /* Caching functions */
1201
1202 # checkLastModified returns true iff it has taken care of all
1203 # output to the client that is necessary for this request.
1204 # (that is, it has sent a cached version of the page)
1205 function tryFileCache() {
1206 static $called = false;
1207 if( $called ) {
1208 wfDebug( " tryFileCache() -- called twice!?\n" );
1209 return;
1210 }
1211 $called = true;
1212 if($this->isFileCacheable()) {
1213 $touched = $this->mTouched;
1214 if( strpos( $this->mContent, "{{" ) !== false ) {
1215 # Expire pages with variable replacements in an hour
1216 $expire = wfUnix2Timestamp( time() - 3600 );
1217 $touched = max( $expire, $touched );
1218 }
1219 $cache = new CacheManager( $this->mTitle );
1220 if($cache->isFileCacheGood( $touched )) {
1221 global $wgOut;
1222 wfDebug( " tryFileCache() - about to load\n" );
1223 $cache->loadFromFileCache();
1224 return true;
1225 } else {
1226 wfDebug( " tryFileCache() - starting buffer\n" );
1227 if($cache->useGzip() && wfClientAcceptsGzip()) {
1228 /* For some reason, adding this header line over in
1229 CacheManager::saveToFileCache() fails on my test
1230 setup at home, though it works on the live install.
1231 Make double-sure... --brion */
1232 header( "Content-Encoding: gzip" );
1233 }
1234 ob_start( array(&$cache, 'saveToFileCache' ) );
1235 }
1236 } else {
1237 wfDebug( " tryFileCache() - not cacheable\n" );
1238 }
1239 }
1240
1241 function isFileCacheable() {
1242 global $wgUser, $wgUseFileCache, $wgShowIPinHeader;
1243 global $action, $oldid, $diff, $redirect, $printable;
1244 return $wgUseFileCache
1245 and (!$wgShowIPinHeader)
1246 and ($this->getID() != 0)
1247 and ($wgUser->getId() == 0)
1248 and (!$wgUser->getNewtalk())
1249 and ($this->mTitle->getNamespace != Namespace::getSpecial())
1250 and ($action == "view")
1251 and (!isset($oldid))
1252 and (!isset($diff))
1253 and (!isset($redirect))
1254 and (!isset($printable))
1255 and (!$this->mRedirectedFrom);
1256 }
1257
1258 function checkTouched() {
1259 $id = $this->getID();
1260 $sql = "SELECT cur_touched,cur_is_redirect FROM cur WHERE cur_id=$id";
1261 $res = wfQuery( $sql, DB_READ, "Article::checkTouched" );
1262 if( $s = wfFetchObject( $res ) ) {
1263 $this->mTouched = $s->cur_touched;
1264 return !$s->cur_is_redirect;
1265 } else {
1266 return false;
1267 }
1268 }
1269 }
1270
1271 function wfReplaceSubstVar( $matches ) {
1272 return wfMsg( $matches[1] );
1273 }
1274
1275 ?>